package com.navinfo.platform.bigdata.dto;

import com.navinfo.platform.bigdata.util.EntityConvert;
import com.navinfo.stream.qingqi.protocol.java.LCAreaType;
import com.navinfo.stream.qingqi.protocol.java.LCLocationData.KeyPointFenceAddition;

public class DefenceAdditionDto {
    private String areaType;
    private long areaId;
    private boolean fenceAlarm;

    public String getAreaType() {
        return areaType;
    }
    public void setAreaType(String areaType) {
        this.areaType = areaType;
    }
    public long getAreaId() {
        return areaId;
    }
    public void setAreaId(long areaId) {
        this.areaId = areaId;
    }
    public boolean isFenceAlarm() {
        return fenceAlarm;
    }
    public void setFenceAlarm(boolean fenceAlarm) {
        this.fenceAlarm = fenceAlarm;
    }

    /**
     * 解析成String拼接字符串
     * @param fenceAddition
     * @return
     */
    public static String parseString(KeyPointFenceAddition fenceAddition){
        return EntityConvert.convert(
                    fenceAddition.getAreaId(),
                    fenceAddition.getAreaType().getNumber(),
                    fenceAddition.getFenceAlarm()
        );
    }

    /**
     * 反解析成PB对象
     * @param fenceAddition
     * @return
     */
    public static KeyPointFenceAddition parsePB(String fenceAddition){
        KeyPointFenceAddition.Builder builder = null;
        try{
            String[] revert = EntityConvert.revert(fenceAddition);
            if(null!=revert && revert.length>=3){
                builder = KeyPointFenceAddition.newBuilder();
                builder.setAreaId(Long.valueOf(revert[0]));
                builder.setAreaType(LCAreaType.AreaType.valueOf(revert[1]));
                builder.setFenceAlarm(Boolean.valueOf(revert[2]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return builder==null? null : builder.build();
    }
}
